import 'package:app/components/button/index.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';


class Confirm {

  BuildContext? context;

  static Confirm of(BuildContext context){
    Confirm confirm = Confirm();
    confirm.context = context;
    return confirm;
  }

  void show(String text, Function()? ok){
    showText(text, ok, null, null);
  }

  void showText(String text, Function()? ok, String? cancelLabel, String? okLabel){
    showDialog(context: context!, builder: (context){
      return AlertDialog(
        title: const Row(
          children: [
            Icon(Icons.warning_amber_outlined, color: Colors.amber,),
            Padding(
              padding: EdgeInsets.only(left: 10),
              child: Text('提示', style: TextStyle(fontWeight: FontWeight.w600),),
            )
          ],
        ),
        content: Text(text??''),
        actions: [
          Container(
            width: MediaQuery.of(context).size.width,
            height: 50,
            decoration: const BoxDecoration(
              border: Border(
                top: BorderSide(color: Color.fromARGB(255, 243, 243, 243), width: 1.0), // 设置下边框样式
              ),
            ),
            child: Row(
              children: [
                Expanded(
                  child: Button(
                    onPressed: () => Navigator.of(context).pop(),
                    label: cancelLabel??'取消',
                    fontSize: 15,
                    fontWeight: FontWeight.w600,
                    backgroundColor: const Color.fromARGB(255, 255, 255, 255),
                    borderColor: const Color.fromARGB(255, 255, 255, 255),
                    fontColor: const Color.fromARGB(255, 0, 0, 0),
                  ),
                ),
                Expanded(
                  child: Button(
                    onPressed: () => ok!(),
                    label: okLabel??'确认',
                    fontSize: 15,
                    fontWeight: FontWeight.w600,
                    backgroundColor: const Color.fromARGB(255, 255, 255, 255),
                    borderColor: const Color.fromARGB(255, 255, 255, 255),
                    fontColor: const Color.fromARGB(255, 0, 0, 0),
                  ),
                )
              ],
            ),
          )
        ],
      );
    });
  }
}